package ${basePackage}.generator;

import freemarker.template.TemplateException;
import ${basePackage}.generator.file.DynamicGenerator;
import ${basePackage}.generator.file.StaticGenerator;
import java.io.File;
import java.io.IOException;
import ${basePackage}.model.DataModel;

<#macro generateFile ident fileInfo>
${ident}inputPath=new File(inputRootPath,"${fileInfo.inputPath}").getAbsolutePath();
${ident}outputPath=new File(outputRootPath,"${fileInfo.outputPath}").getAbsolutePath();
<#if fileInfo.type=="static">
${ident}StaticGenerator.copyFileByHutool(inputPath,outputPath);
<#else>
${ident}DynamicGenerator.doGenerate(inputPath,outputPath,model);
</#if>
</#macro>
/**
 * @version ${version}
 * @Author ${author}
 * @Date ${createTime}
 * @注释 动静结合
 */
public class MainGenerator {


    public static void doGenerate(DataModel model) throws IOException, TemplateException {
        String inputRootPath = "${fileConfig.inputRootPath}";
        String outputRootPath="${fileConfig.outputRootPath}";

        String inputPath;
        String outputPath;
<#list modelConfig.models as modelInfo>
    //有分组
    <#if modelInfo.groupKey??>
    <#list modelInfo.models as subModelInfo>
        ${subModelInfo.type} ${subModelInfo.fieldName}=model.${modelInfo.groupKey}.${subModelInfo.fieldName};
    </#list>
    <#else >
        ${modelInfo.type} ${modelInfo.fieldName}=model.${modelInfo.fieldName};
    </#if>

</#list>
<#list fileConfig.files as fileInfo>
    <#if fileInfo.groupKey??>
        <#if fileInfo.condition??>
        if(${fileInfo.condition}){
        <#list fileInfo.files as fileInfo>
            <@generateFile ident="              " fileInfo=fileInfo></@generateFile>
        </#list>

        }
        <#else >
            <#list fileInfo.files as fileInfo>
                <@generateFile ident="          " fileInfo=fileInfo></@generateFile>
            </#list>

        </#if>

    <#else >
        <#if fileInfo.condition??>
        if(${fileInfo.condition}){
        <@generateFile ident="              " fileInfo=fileInfo></@generateFile>
        }

        <#else >
            <@generateFile ident="         " fileInfo=fileInfo></@generateFile>

        </#if>
    </#if>

</#list>

    }

}
